//
//  LoadDataFromNetWork.m
//  Alltelevisionnews
//
//  Created by dllo on 15/11/30.
//  Copyright © 2015年 三人行. All rights reserved.
//

#import "SLLoadModelFromNetWork.h"
#import "SLAFNetWorkTool.h"
#import "SLVideoCellModel.h"


@implementation SLLoadModelFromNetWork

+ (void)loadModelWithIndex:(NSInteger)pageIndex success:(SUCCESS_BLOCK)successBlock failure:(FAILURE_BLOCK)failureBlock
{
    NSInteger index = pageIndex * 10;
    
    NSString *URLStr = [NSString stringWithFormat:@"http://c.m.163.com/nc/video/home/%ld-10.html",index];
    
    [SLAFNetWorkTool cacheGetWithURL:URLStr cookie:nil success:^(id responseObject) {
        
        id modelObject = [self convertToModelObject:responseObject];
        
        successBlock(modelObject);
        
    } failure:^(NSError *error) {
        
        failureBlock(error);
        
    }];
}

+ (id)convertToModelObject:(id)responseObject
{
    NSDictionary *dic = responseObject;
    NSArray *array = [SLVideoCellModel baseModelByArr:dic[@"videoList"]];
    
    return array;
}

@end
